const path = require('path')
var name = path.basename(__filename, '.js')//本文件名
var resolve = (recvStr) => {
    var arr = recvStr.split(',')
    var result = {}
    if (!arr | arr.length != 21) {
        console.log(arr.length)
        result.status = false
        result.msg = '数据长度错误'
    } else {
        result.status = true
        result.msg = 'ok'
        result.data = {}
        result.data.ch1value = arr[0]
        result.data.ch2value = arr[1]
        result.data.ch3value = arr[2]
        result.data.ch4value = arr[3]
        result.data.ch5value = arr[4]
        result.data.ch6value = arr[5]
        result.data.ch7value = arr[6]
        result.data.ch8value = arr[7]
        result.data.totalJudge = arr[8].trim()
        result.data.ch1judge = arr[9].trim()
        result.data.ch2judge = arr[10].trim()
        result.data.ch3judge = arr[11].trim()
        result.data.ch4judge = arr[12].trim()
        result.data.ch5judge = arr[13].trim()
        result.data.ch6judge = arr[14].trim()
        result.data.ch7judge = arr[15].trim()
        result.data.ch8judge = arr[16].trim()
        result.data.type = arr[17].trim()
        result.data.date = arr[19]
        result.data.time = arr[20]
        result.data.timeStamp=Date.now()
        // console.log(result.data.timeStamp)
    }
    return result
}

var parserRule=(port)=>{
    var Readline = require('@serialport/parser-readline')
    var ByteLength = require('@serialport/parser-byte-length')//指定数据帧字节长度，略
    var parser = port.pipe(new Readline({delimiter: '\r\n'}))//以回车换行为结束标记
    return parser
}

module.exports = {
    name,
    parserRule,
    resolve
}